#include "compile_run.hpp"
#include "../comm/httplib.h"

using namespace ns_compile_and_run;
using namespace httplib;

void Usage(string proc)
{
    std::cerr << "Usage:\n\t" << proc << " port\n";
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        return 1;
    }

    Server svr;
    svr.Post("/compile_and_run", [](const Request &req, Response &resp)
             {
        string in_json = req.body;
        string out_json;
        if(!in_json.empty())
        {
            ComplieAndRun::Start(in_json,&out_json);
            resp.set_content(out_json,"application/json;charset=UTF-8;");
        } });

    svr.listen("0.0.0.0", atoi(argv[1]));
    return 0;
}